async function main(nums) {
  // get all zeroIndex(num===0)
  const zeroIndexList = findTargetNumIndexs(nums, (num) => !num)
  const isCurrentZero = !!zeroIndexList.length
  zeroIndexList.push(Infinity)

  //  generate num fragment
  let beforeZeroNumber = 0
  const fragmentList = zeroIndexList
    .map((zeroIndex, index) => {
      // is fisrt numZero
      if (!zeroIndex && isCurrentZero) {
        // NOTE: index:0  zeroValue:0
        beforeZeroNumber = zeroIndex === 0 ? 1 : 0
        return void 0
      }

      const fragment = nums.slice(beforeZeroNumber, zeroIndex)
      beforeZeroNumber = zeroIndex + 1

      return fragment.length ? fragment : void 0
    })
    .filter(Boolean)

  // promise list
  const PromiseList = []
  fragmentList.forEach((fragment) => {
    PromiseList.push(calculateMaxProduct(fragment))
  })

  const maxCount = Promise.all(PromiseList).then((...count) => {
    return isCurrentZero ? Math.max(...count[0], 0) : Math.max(...count[0])
  })

  return maxCount
}

/** 异步计算最大乘积 */
function calculateMaxProduct(numFramgent) {
  return new Promise((resolve, reject) => {
    // num framgent 长度只是为1
    if (numFramgent.length === 1) return resolve(numFramgent[0])

    // 获取该片段中 小于0的所有数据集合
    const negativeNumbers = findTargetNumIndexs(numFramgent, (num) => num < 0)
    const numberLength = negativeNumbers.length

    // 基数偶数判断 negativeNumbers.length （前提： 都是整数）
    const isEven = numberLength % 2 === 0
    if (isEven) {
      const result = handleProductCalculation(numFramgent)
      return resolve(result)
    } else {
      // 奇数 分为两种情况 （留下最后，留下最前 ： 取最长）
      const firstIndex = negativeNumbers[0]
      const endIndex = negativeNumbers.slice(-1)[0]

      const leftResult = handleProductCalculation(
        numFramgent.slice(0, endIndex)
      )
      const rightResult = handleProductCalculation(
        numFramgent.slice(firstIndex, numberLength)
      )

      return resolve(Math.max(leftResult, rightResult))
    }
  })
}

/**
 *  generate target num indexs
 * @param {Array<number>} targetList
 * @param {Function} fn
 * @returns
 */
function findTargetNumIndexs(targetList, fn) {
  try {
    return targetList
      .map((num, index) => (fn(num) ? index : NaN))
      .filter((_) => !isNaN(_))
  } catch (e) {
    return []
  }
}

/**
 * 集合乘积计算
 * @param {Array<number>} targetList
 */
function handleProductCalculation(targetList) {
  // 如果是偶数所有数据点积
  const initialValue = 1
  const sumWithInitial = targetList.reduce(
    (previousValue, currentValue) => previousValue * currentValue,
    initialValue
  )

  return sumWithInitial
}

main([2, 3, -2, 4]).then(console.log)
